App({


    onLaunch:function(){
      return;
        wx.request({
          url: 'https://bja1.selfapp.catflytech.com/debug.php',
          data: {name:'xyz'},
          method: 'GET', 
          // header: {}, // 设置请求的 header
          success: function(res){
           // console.log(res);
          },
          fail: function() {
            // fail
          },
          complete: function() {
            // complete
          }
        })
    },
    host:'https://bja1.selfapp.catflytech.com',
    path:'/minicard/main/',
    s3:function(){
      return wx.getStorageSync('sss');
    },
    //alert
    //传入字符串
    //多用于失败反馈
    alert:function(str){
       wx.showModal({
            content: str,
            showCancel: false,
           });
    },
    //吐司
    //传入字符串
    //成功反馈
    toast:function(str){
        wx.showToast({
            title: str,
            icon: 'success',
            duration: 10000,
            mask:true
        });

    },
    //吐司-载入中,取消载入
    //传入字符串
    loading:function(str){
      str=str || '载入中';
      wx.showToast({
         title:str,
         icon:'loading',
         duration: 10000,
         mask:true
      })
    },
    hidetoast:function(){
      wx.hideToast();
    },
    //跳转,当前页面打开
    to:function(url){
      wx.redirectTo({
        url: url  
      })
    },
    //跳转,新页面打开
    tonew:function(url){
      wx.navigateTo({
        url: url
      });
    },
    //login
    //登录获取3s
    //需要一个回调
    login:function(cb){
        var app=this;

        wx.login({
        success: function(res){
        if(res.code)
        {
            wx.request({
              url: app.host+app.path+'login',
              data: {code:res.code},
              method: 'POST', 
              success: function(res){
                   cb(res);
              },
              fail: function() {
                   app.alert('网络连接失败');
              },
              complete: function() {
              }
            })
        }
        else
        {
            wx.showModal({
            content: '登录失败',
            showCancel: false,
            success: function (res) {}});
        }
      },
      fail: function() {
          app.alert('网络连接失败');
      },
      complete: function() {
        
      }
    })

    },

    //upuserinfo
    //上传用户信息
    //输入sss,回调
    uploadinfo:function(sss,cb){
      var app=this;
      //res1 用户信息 res2 地理位置 res3 手机信息
      var res1,res2,res3;

      var upload=function(sss,cb){
       // console.log(res1,res2,res3);
        wx.request({
          url: app.host+app.path+'nowuser',
          data: {
              avatar:res1.userInfo.avatarUrl,
              city:res1.userInfo.city,
              country:res1.userInfo.country,
              gender:res1.userInfo.gender,
              language:res1.userInfo.language,
              nickname:res1.userInfo.nickName,
              province:res1.userInfo.province,
              log:res2.longitude,
              lat:res2.latitude,
              model:res3.model,
              sss:sss
          },
          method: 'POST',
          success: function(res){
            cb(res);
          },
          fail: function() {
            app.alert('网络连接失败');
          },
          complete: function() {
          }
        })

      }

      wx.getUserInfo({
        success: function(res){
           res1=res;
           if(Boolean(res1 && res2 && res3)){upload(sss,cb);};
        },
        fail: function() {
          app.alert('网络连接失败');
        },
        complete: function() {
          // complete
        }
      });

      wx.getLocation({
        type: 'gcj02', // 默认为 wgs84 返回 gps 坐标，gcj02 返回可用于 wx.openLocation 的坐标
        success: function(res){
          res2=res;
         if(Boolean(res1 && res2 && res3)){upload(sss,cb);};
        },
        fail: function() {
          app.alert('网络连接失败');
        },
        complete: function() {
          // complete
        }
      });

      wx.getSystemInfo({
        success: function(res) {
          res3=res;
          if(Boolean(res1 && res2 && res3)){upload(sss,cb);};
        }
      });

      

    }
    //end
});